public class TestDemo {
    public static ListNode mergeTwoLists(ListNode headA,ListNode headB){
        ListNode newHead=new ListNode(-1);
        ListNode tmp=newHead;
        while(headA!=null&&headB!=null){
            if (headA.val<headB.val){
                tmp.next=headA;
                headA=headA.next;
                tmp=tmp.next;
            }else{
                tmp.next=headB;
                headB=headB.next;
                tmp=tmp.next;
            }
        }
        if (headA!=null){
            tmp.next= headA;
        }
        if (headB!=null){
            tmp.next= headB;
        }
        return  newHead.next;
    }
    public static void main1(String[] args) {
        MyLinkedList myLinkedList=new MyLinkedList();
        myLinkedList.addLast(12);
        myLinkedList.addLast(23);
        myLinkedList.addLast(34);
        myLinkedList.addLast(45);

        MyLinkedList myLinkedList2=new MyLinkedList();
        myLinkedList2.addLast(13);
        myLinkedList2.addLast(24);
        myLinkedList2.addLast(30);

       /* myLinkedList.addFirst(156);
        myLinkedList.addIndex(0,99);
        myLinkedList.display();
        boolean flg=myLinkedList.contains(56);
        System.out.println(flg);
        myLinkedList.remove(34);
        myLinkedList.display();
        myLinkedList.clear();
        System.out.println("adadas");*/
      /*  ListNode ret=myLinkedList.reverseList();
        myLinkedList.display2(ret);
        ListNode ret1=myLinkedList.FindKthToTail(2);
        System.out.println(ret1.val);*/
        ListNode ret2= mergeTwoLists(myLinkedList.head,myLinkedList2.head);
        myLinkedList.display2(ret2);
    }

    public static void main(String[] args) {
        MyLinkedList myLinkedList=new MyLinkedList();
        myLinkedList.addLast(12);
        myLinkedList.addLast(23);
        myLinkedList.addLast(34);
        myLinkedList.addLast(45);
        myLinkedList.addLast(56);
        //myLinkedList.createLoop();
        System.out.println(myLinkedList.hasCycle());
    }
}





























